package com.android.audio;

import android.media.MediaRecorder;
import android.os.Environment;

public class AudioRecorder {
	
	private MediaRecorder recorder;
	private String path;
	
	public AudioRecorder(String filname){
		path = SetPath(filname);
	}
	
	private String SetPath(String filname){
		return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + filname + ".mp4";
	}
	
	public void record(){
		
		recorder = new MediaRecorder();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
	    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
	    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
	    recorder.setOutputFile(path);
	    
	    try {
			recorder.prepare();
		} catch (Exception e) {
			e.printStackTrace();
		} 
	    recorder.start();  
	}
	
	public void stop(){
		 recorder.stop();
         recorder.release();
         recorder = null;
	}
	

}
